<?php

namespace app\api\validate;

use app\common\validate\BaseValidate;

class AddressBook extends BaseValidate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'cityCode' => 'number|length:6',
        'cityName' => 'regex:/^[\x{4e00}-\x{9fa5}]{2,20}$/u',
        'consigneeName' => 'checkMixedString:min=2,max=20', // 姓名：2-20位混合字符
        'detail' => 'require',
        'districtCode' => 'number|length:2',
        'districtName' => 'regex:/^[\x{4e00}-\x{9fa5}]{2,20}$/u',
        'id' => 'require|integer',
        'isDefault' => 'integer|in:0,1',
        'label' => 'checkMixedString:min=1,max=20',
        'phone' => 'require|checkMobile',
        'provinceCode' => 'number|length:2',
        'provinceName' => 'regex:/^[\x{4e00}-\x{9fa5}]{2,20}$/u',
        'sex' => 'require',
        'userId' => 'integer',
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'cityCode.number'  => '城市编码必须为数字',
        'cityCode.length'  => '城市编码必须为6位',
        'cityName.regex'   => '城市名称需为2-20位汉字，无其他字符',
        'consigneeName.checkMixedString' => '收货人姓名需为2-20位汉字/字母/数字，无非法字符',
        'detail.require' => '地址详情必须',
        'districtCode.number'   => '区县编码必须为数字',
        'id.integer' => 'id必须为数字',
        'phone.require' => '手机号必须',
        'provinceCode.number' => '省份编码必须为数字',
        'sex.require' => '性别必须',
        'userId.integer' => '用户id必须为数字',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['cityCode', 'cityName', 'consigneeName', 'detail', 'districtCode', 'districtName','isDefault', 'label', 'phone', 'provinceCode', 'provinceName', 'sex', 'userId'],
        'update'  => ['id','cityCode', 'cityName', 'consigneeName', 'detail', 'districtCode', 'districtName', 'id', 'isDefault', 'label', 'phone', 'provinceCode', 'provinceName', 'sex', 'userId'],
        'delete' => ['id'],
        'setDefault' => ['id'],
    ];
}
